package unitTest;

import com.mic.yzzn.plc.core.control.datastructure.PLCStationConfig;

import java.util.ArrayList;

/**
 * Created by ASH on 16/5/17.
 */
public class TestMain
{
    public static void main(String[] args)
    {
        PLC_TestXMLParser parser = new PLC_TestXMLParser();
        int interval = 1; // 发送任务的间隔时间

        try
        {
            parser.parseXMLFileFromURI("Test-Config.xml");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

        ArrayList<PLCStationConfig> stationConfigs = parser.getstationConfigs();
        for (PLCStationConfig stationConfig : stationConfigs)
        {
            int bufferdReadCount = parser.getStationBufferdReadThreadNumber().get(stationConfig.XMLFieldHashCode);
            int realtimeReadCount = parser.getStationRealTimeReadThreadNumber().get(stationConfig.XMLFieldHashCode);
            int realtimeWriteCount = parser.getStationRealTimeWriteThreadNumber().get(stationConfig.XMLFieldHashCode);

            for (int j = 0; j < bufferdReadCount; ++j)
            {
                ConfigBuffredReadTest cbt = new ConfigBuffredReadTest();
                cbt.threadName = stationConfig.id() + " " + (j + 1) + "号缓存读取线程: " + stationConfig.XMLFieldHashCode.substring(0, 3);
                cbt.stationConfig = stationConfig;
                cbt.dPoints = parser.getBuffredReadDPointsMap().get(stationConfig.XMLFieldHashCode);
                cbt.rPoints = parser.getBuffredReadRPointsMap().get(stationConfig.XMLFieldHashCode);
                (new Thread(cbt)).start();
            }

            for (int j = 0; j < realtimeReadCount; ++j)
            {
                ConfigRealTimeReadTest crt = new ConfigRealTimeReadTest();
                crt.stationConfig = stationConfig;
                crt.threadName = stationConfig.id() + " " + (j + 1) + "号实时读取线程: " + stationConfig.XMLFieldHashCode.substring(0, 3);
                (new Thread(crt)).start();
            }

            for (int j = 0; j < realtimeWriteCount; ++j)
            {
                ConfigRealTimeWriteTest cwt = new ConfigRealTimeWriteTest();
                cwt.stationConfig = stationConfig;
                cwt.threadName = stationConfig.id() + " " + (j + 1) + "号实时写入线程: " + stationConfig.XMLFieldHashCode.substring(0, 3);
                cwt.writeInstructions = parser.getWriteInstructionsMap().get(stationConfig.XMLFieldHashCode);
                (new Thread(cwt)).start();
            }
        }

    }
}
